package com.hzdl.controller;

import com.hzdl.bean.Project;
import com.hzdl.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * create by zy on 2018\9\5 0005
 */
@Controller
@RequestMapping("/project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;
    /**
     * 添加项目
     * @return
     */
    @RequestMapping("/addProject")
    public  String addProject(Project project){
        projectService.addProject(project);
        return "success";
    }
    @RequestMapping("/toAddProject")
    public  String toAddProject(){

        return "addproject";
    }

    /**
     * 获取所有项目信息
     */
    @RequestMapping("/getAllProjects")
    public String getAllProjects(Model model){
        List<Project> projects=projectService.getAllProjects();
        model.addAttribute("projects",projects);
        return "project";
    }
    /**
     *查看指定id的项目信息
     */

    @RequestMapping("/getProjectById")
    public String getProjectById(long id,Model model){
        Project project = projectService.getProjectById(id);
        model.addAttribute("project",project);
        return "project_detail";
    }

    /**
     * 编辑项目
     */
    @RequestMapping("updateProject")
    public String updateProject(Project project){

        projectService.updateProject(project.getPname(),project.getCompany(),project.getAddress(),project.getId());
        return "forward:/project/getAllProjects";
        }
     @RequestMapping("/toUpdateProject")
      public String toUpdateProject(long id,Model model){
        Project project = projectService.getProjectById(id);
        model.addAttribute("project",project);
        return "editproject";
    }
//    @RequestMapping("getAllProjectsByC")
//    public String getAllProjectsByC(int company, Model model){
//        System.err.println(company);
//        List<Project> ps= projectService.getAllProjectsByC(company);
//        model.addAttribute("ps",ps);
//        return "company";
//    }
}